﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WSAP;

namespace CouplingBeamProject
{
    /// <summary>
    /// 单元信息
    /// </summary>
    class Element : Rectangular
    {
        /// <summary>
        /// J端节点坐标
        /// </summary>
        private Node nodeJ { set; get; }

        /// <summary>
        /// K端节点坐标
        /// </summary>
        private Node nodeK { set; get; }

        /// <summary>
        /// L端节点坐标
        /// </summary>
        private Node nodeL { set; get; }

        /// <summary>
        /// 添加单元
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public bool AddElement(WModelNet model,double thickfactor)
        {
            if (this.GetMaterial().GetE() == 0)
            {
                return true;
            }
            else
            {
                return model.AddShell(this.LeftDownNode.Index, this.nodeJ.Index, this.nodeK.Index, this.nodeL.Index,
               this.GetMaterial().GetE(), this.GetMaterial().GetPossionRatio(), GlobalVar.Thickness * thickfactor) != null;
            }
            //return model.AddShell(this.LeftDownNode.Index, this.nodeJ.Index, this.nodeK.Index, this.nodeL.Index,
            //this.GetMaterial().GetE(), this.GetMaterial().GetPossionRatio(), GlobalVar.Thickness * thickfactor) != null;
        }

        /// <summary>
        /// 获得单个单元所有节点
        /// </summary>
        public List<Node> GetNodeList()
        {
            return new List<Node>
                {
                    this.LeftDownNode, 
                this.nodeJ, this.nodeK, this.nodeL
                };
        }

        /// <summary>
        /// 构造函数
        /// </summary>
        public Element(double width, double height, double x, double y, Material material)
            : base(width, height, x, y, material)
        {
            this.nodeJ = new Node(x + this.Width, y);
            this.nodeK = new Node(x + this.Width, y + this.Height);
            this.nodeL = new Node(x, y + this.Height);
        }
    }
}
